﻿using System;
using System.Collections.Generic;
using Socium.Domain.Collections;
using Socium.Domain.Persons;

namespace Socium.Domain.Tests.Sociometric {
	[Serializable]
	public class Procedure {
		public string Name { get; set; }
		public string Description { get; set; }

		public DateTime Date { get; set; }

		readonly ICollection<ElectionCriteria> _election_criterias = new LinkedList<ElectionCriteria>();
		readonly ICollection<Election> _elections = new LinkedList<Election>();

		public ICollection<ElectionCriteria> ElectionCriterias {
			get { return _election_criterias; }
		}

		public ICollection<Election> Elections {
			get { return _elections; }
		}

		public override string ToString() {
			return !string.IsNullOrEmpty(Name) ? Name : string.Format("Procedure {0}", Date);
		}

		public void RemovePerson(Person person) {
			var elections_to_delete = _elections.Filter(election => election.Elector == person || election.Elected == person);
			elections_to_delete.Iterate(election => _elections.Remove(election));
		}
	}
}
